home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / pdcurs21 / portable / initpair.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  3.8 KB  |  90 lines

  1. #define    CURSES_LIBRARY    1
  2. #include <curses.h>
  3. #undef init_pair
  4.  
  5. #ifdef PDCDEBUG
  6. char *rcsid_initpair = "$Header: C:\CURSES\portable\RCS\initpair.c 2.1 1993/06/18 20:20:09 MH Rel MH $";
  7. #endif
  8.  
  9.  
  10.  
  11.  
  12. /*man-start*********************************************************************
  13.  
  14.   initpair()    - Change the definition of a color-pair.
  15.  
  16.   PDCurses Description:
  17.  
  18.      This routine is used to change the definition of a color-pair.
  19.      The routine takes three arguments: the number of the color-pair
  20.      to be redefined, and the new values of the foreground and
  21.      background colors.
  22.  
  23.      The value of colorpair must be between 1 and COLOR_PAIRS-1.
  24.      The values of foreground and background must be between 0 and
  25.      COLORS-1.
  26.  
  27.   PDCurses Return Value:
  28.      This function returns OK on success and ERR on error.
  29.  
  30.   PDCurses Errors:
  31.      It is an error to call this function with values outside of the
  32.      ranges specified above.
  33.  
  34.   Portability:
  35.      PDCurses    int init_pair( int colorpair, short foreground, short background);
  36.      SYS V Curses    int init_pair( int colorpair, short foreground, short background);
  37.  
  38. **man-end**********************************************************************/
  39.  
  40. unsigned char    atrtab[MAX_ATRTAB] = /* COLOR_PAIR to attribute encoding table. */
  41.  {0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  42.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  43.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  44.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  45.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  46.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  47.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  48.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  49.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  50.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  51.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  52.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  53.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  54.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  55.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  56.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  57.   0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,0x07,0x0F,0x70,0x78,0x87,0x8F,0xF0,0xF8,
  58.   0x70,0x00,0x17,0x00,0x00,0x00,0x00,0x00
  59.   };
  60.  
  61. int init_pair(int colorpair,short foreground,short background)
  62. {
  63.  extern int COLOR_PAIRS;
  64.  unsigned char norm,reverse;
  65.  
  66. #ifdef PDCDEBUG
  67.     if (trace_on) PDC_debug("init_pair() - called: colorpair %d fore %d back %d\n",colorpair,foreground,background);
  68. #endif
  69.  
  70.  if (colorpair >= COLOR_PAIRS || colorpair < 1)
  71.     return(ERR);
  72.  
  73.  norm = (unsigned char)(foreground & 0x0007) + ((background & 0x0007)<<4);
  74.  reverse = (unsigned char)(background & 0x0007) + ((foreground & 0x0007)<<4);
  75.  
  76. #ifdef CHTYPE_LONG
  77.  atrtab[colorpair] = norm;
  78. #else
  79.  atrtab[(colorpair*8)+0] = norm;                             /* normal */
  80.  atrtab[(colorpair*8)+1] = norm + 8;                       /* bold */
  81.  atrtab[(colorpair*8)+2] = reverse;                     /* reverse */
  82.  atrtab[(colorpair*8)+3] = reverse + 8;            /* bold-reverse */
  83.  atrtab[(colorpair*8)+4] = norm + 128;                    /* blink */
  84.  atrtab[(colorpair*8)+5] = norm + 8 + 128;           /* bold-blink */
  85.  atrtab[(colorpair*8)+6] = reverse + 128;         /* reverse-blink */
  86.  atrtab[(colorpair*8)+7] = reverse + 8 + 128;/* reverse-bold-blink */
  87. #endif
  88.  return(OK);
  89. }
  90.